﻿using System.Security.Permissions;
using System.Windows.Forms;
using System;

namespace GordonKristan.cppcheck
{
	/// <summary>
	/// Summary description for MyControl.
	/// </summary>
	public partial class ToolWindowControl : UserControl
	{
		public ToolWindowControl()
		{
			InitializeComponent();
		}

		/// <summary> 
		/// Let this control process the mnemonics.
		/// </summary>
		[UIPermission(SecurityAction.LinkDemand, Window = UIPermissionWindow.AllWindows)]
		protected override bool ProcessDialogChar(char charCode)
		{
			// If we're the top-level form or control, we need to do the mnemonic handling
			if (charCode != ' ' && ProcessMnemonic(charCode))
			{
				return true;
			}
			return base.ProcessDialogChar(charCode);
		}

		/// <summary>
		/// Enable the IME status handling for this control.
		/// </summary>
		protected override bool CanEnableIme
		{
			get
			{
				return true;
			}
		}

		/// <summary>
		/// Adjusts the last column to fill the whole window.
		/// </summary>
		private void AdjustViewColumns()
		{
			//Get the window width
			int fullWidth = this.Width - SystemInformation.VerticalScrollBarWidth - 8;
			//Subtract off the first n-1 column widths
			for (int xx = 0; xx < listView.Columns.Count; ++xx)
			{
				fullWidth -= listView.Columns[xx].Width;
			}
			// Widen last column to fill view 
			listView.Columns[listView.Columns.Count - 1].Width += fullWidth;
		}

		/// <summary>
		/// Overridden resize event. We use it to resize the list view.
		/// </summary>
		/// <param name="e">Reisze details</param>
		protected override void OnResize(EventArgs e)
		{
			AdjustViewColumns();
			base.OnResize(e);
		}
	}
}
